local _, GrifonOvaleScripts = ...

GrifonOvaleScripts.script.WARLOCK.Attilio = {
	desc = "[5.4] Attilio: Destruction ",
	code =
[[

#Spells
Define(agony 980)
        SpellInfo(agony duration=24 haste=spell tick=2)
        SpellAddTargetDebuff(agony agony=1)
Define(backdraft 117896)
        SpellAddBuff(backdraft backdraft=1)
Define(blood_fear 5782)
        SpellInfo(blood_fear cd=10)
Define(blood_fury 20572)
        SpellInfo(blood_fury duration=15 cd=120)
        SpellAddBuff(blood_fury blood_fury=1)
Define(chaos_bolt 116858)
	SpellInfo(chaos_bolt burningembers=10 haste=spell tick=1)
	SpellAddTargetDebuff(chaos_bolt chaos_bolt=1)
Define(conflagrate 17962)
        SpellInfo(conflagrate duration=5)
        SpellAddTargetDebuff(conflagrate conflagrate=1)
Define(corruption 172)
Define(corruption_aura 146739)
        SpellInfo(corruption_aura duration=18 haste=spell tick=2 stance=0)
        SpellAddTargetDebuff(corruption_aura corruption_aura=1)
Define(create_healthstone 6201)
Define(curse_of_the_elements 1490)
        SpellInfo(curse_of_the_elements duration=300)
        SpellAddTargetDebuff(curse_of_the_elements aura_of_the_elements=1)
Define(curse_of_enfeeblement 109466)
        SpellInfo(curse_of_enfeeblement duration=30)
        SpellAddTargetDebuff(curse_of_enfeeblement curse_of_enfeeblement=1)
Define(curse_of_exhaustion 18223)
        SpellInfo(curse_of_exhaustion duration=30)
        SpellAddTargetDebuff(curse_of_exhaustion curse_of_exhaustion=1)
Define(dark_intent 109773)
        SpellInfo(dark_intent duration=3600)
        SpellAddBuff(dark_intent dark_intent=1)
Define(dark_soul_misery 113860)
        SpellInfo(dark_soul_misery cd=120)
Define(dark_soul_instability 113858)
        SpellInfo(dark_soul_instability cd=120)
Define(doom 603)
        SpellInfo(doom duration=60 demonicfury=60 haste=spell tick=15 stance=1)
        SpellAddTargetDebuff(doom doom=1)
Define(drain_soul 1120)
        SpellInfo(drain_soul duration=12 haste=spell tick=2 canStopChannelling=1)
        SpellAddTargetDebuff(drain_soul drain_soul=1)
Define(fel_flame 77799)
Define(felstorm 89751)
        SpellInfo(felstorm duration=6 energy=60 cd=45)
        SpellAddBuff(felstorm felstorm=1)
Define(fire_and_brimstone 108683)
        SpellInfo(fire_and_brimstone burningembers=1 cd=1)
        SpellAddBuff(fire_and_brimstone fire_and_brimstone=1)
Define(grimoire_of_sacrifice 108503)
        SpellInfo(grimoire_of_sacrifice duration=1200 cd=120)
        SpellAddBuff(grimoire_of_sacrifice grimoire_of_sacrifice=1)
Define(hand_of_guldan 105174)
Define(harvest_life 108371)
        SpellInfo(harvest_life duration=6 demonicfury=30 tick=1)
        SpellAddTargetDebuff(harvest_life harvest_life=1)
Define(haunt 48181)
       SpellInfo(haunt duration=8 shards=1 tick=2)
       SpellAddTargetDebuff(haunt haunt=1)
Define(havoc 80240)
        SpellInfo(havoc duration=15 cd=45)
        SpellAddBuff(havoc havoc=1)
	SpellAddTargetDebuff(havoc  havoc =1)
Define(healthstone 5512)
	SpellInfo(healthstone cd=120)
Define(hellfire 1949)
	SpellInfo(hellfire duration=14 haste=spell tick=1 canStopChannelling=1)
	SpellAddTargetDebuff(hellfire hellfire=1)
Define(immolate 348)
        SpellInfo(immolate duration=15 haste=spell tick=3)
        SpellAddTargetDebuff(immolate immolate=1)
Define(immolate_fire_and_brimstone 108686)
        SpellInfo(immolate_fire_and_brimstone duration=15 haste=spell tick=3)
        SpellAddTargetDebuff(immolate_fire_and_brimstone immolate_fire_and_brimstone=1)
Define(immolation_aura 129476)
Define(incinerate_aoe 114654)
Define(incinerate 29722)
	SpellInfo(incinerate burningembers=-1 if_spell=burning_embers)
	SpellInfo(incinerate buff_burningembers=fire_and_brimstone_buff buff_burningembers_amount=11 if_spell=fire_and_brimstone)
	SpellAddBuff(incinerate backdraft_buff=-1 if_spell=backdraft)
Define(life_tap 1454)
        SpellInfo(life_tap mana=-15)
        SpellAddBuff(life_tap life_tap=1)
Define(malefic_grasp 103103)
        SpellInfo(malefic_grasp duration=4 haste=spell tick=1 canStopChannelling=1)
        SpellAddTargetDebuff(malefic_grasp malefic_grasp=1)
Define(melee 103988)
        SpellInfo(melee stance=1)
Define(metamorphosis 103958)
        SpellInfo(metamorphosis demonicfury=0 cd=10)
        SpellAddBuff(metamorphosis metamorphosis=1)
Define(molten_core 122355)
        SpellInfo(molten_core duration=30)
        SpellAddBuff(molten_core molten_core=1)
Define(nightfall 108558)
        SpellAddBuff(nightfall nightfall=1)
#Define(rain_of_fire 42223)
Define(rain_of_fire 104232)
	SpellInfo(rain_of_fire duration=6)
	SpellAddBuff(rain_of_fire rain_of_fire=1 canStopChannelling=1)
Define(seed_of_corruption 27243)
        SpellInfo(seed_of_corruption duration=18 haste=spell tick=3)
        SpellAddTargetDebuff(seed_of_corruption seed_of_corruption=1)
Define(service_felguard 111898)
        SpellInfo(service_felguard cd=120)
Define(service_felhunter 111897)
        SpellInfo(service_felhunter cd=120)
Define(shadow_bolt 686)
        SpellInfo(shadow_bolt demonicfury=40)
Define(shadowburn 17877)
        SpellInfo(shadowburn burningembers=1)
Define(shadowflame 47960)
        SpellInfo(shadowflame duration=6 haste=spell tick=1)
        SpellAddTargetDebuff(shadowflame shadowflame=1)
Define(shadowfury 30283)
        SpellInfo(shadowfury cd=30)
Define(soul_fire 6353)
        SpellAddBuff(soul_fire molten_core=-1)
Define(soul_swap 86121)
Define(soulburn 74434)
        SpellInfo(soulburn duration=30 shards=1 cd=1)
        SpellAddBuff(soulburn soulburn=1)
Define(soulburn_seed_of_corruption 86664)
Define(spell_lock 19647) #Felhunter silence
Define(spell_lock_sacrifice 132409) #Felhunter silence with sacrifice
        SpellInfo(spell_lock cd=24)
Define(Optical_Blast 115781) #Observer silence
        SpellInfo(Optical_Blast cd=24)
Define(touch_of_chaos 103964)
        SpellInfo(touch_of_chaos demonicfury=40 stance=1)
Define(unstable_affliction 30108)
        SpellInfo(unstable_affliction duration=14 haste=spell tick=2)
        SpellAddTargetDebuff(unstable_affliction unstable_affliction=1)
Define(void_ray 115422)
        SpellInfo(void_ray demonicfury=40)
Define(wrathstorm 115831)
        SpellInfo(wrathstorm duration=6 energy=60 cd=45)
        SpellAddBuff(wrathstorm wrathstorm=1)
Define(ember_tap 114635)
Define(cauterize_master 119899)
	SpellInfo(cauterize_master cd=30)

#Spell Lists
SpellList(afflic_combined_dots agony corruption_aura unstable_affliction)
SpellList(destro_combined_dots immolate immolate_fire_and_brimstone)

#Spell/buffs from other sources
Define(skull_banner 114207)
	SpellInfo(skull_banner duration=10 cd=180)

#Demons
Define(summon_doomguard 18540)
        SpellInfo(summon_doomguard cd=600)
Define(summon_infernal 1122)
        SpellInfo(summon_infernal cd=600)
Define(summon_terrorguard 112927)
        SpellInfo(summon_doomguard cd=600)

Define(summon_felhunter 691)
Define(summon_observer 112869)

Define(summon_imp 688)
Define(summon_fel_imp 112866)

Define(summon_succubus 712)
Define(summon_shivarra 112868)

Define(summon_voidwalker 697)
Define(summon_voidlord 112867)

#Procs
Define(lightweave 125487)
        SpellAddBuff(lightweave lightweave=1)
Define(yulons_bite 146218)
        SpellAddBuff(yulons_bite yulons_bite=1)
SpellList(combined_procs lightweave yulons_bite)

#Talents
Define(harvest_life_talent 3)
Define(grimoire_of_supremacy_talent 13)
Define(grimoire_of_service_talent 14)
Define(grimoire_of_sacrifice_talent 15)
Define(cunning_talent 17)

#command demon
Define(command_demon 119898)

#Glyphs
Define(glyph_of_soul_swap 56226)

AddFunction UseItems
{
	Item(HandsSlot usable=1)

}

AddCheckBox(AutoCurseOfElements "AutoCurseOfElements" default)
AddCheckBox(AutoInterrupt "AutoInterrupt" default)
AddCheckBox(AutoDoomGuard "AutoDoomGuard")
AddCheckBox(AutoDarkSoul "AutoDarkSoul" default)
AddCheckBox(ChaosBoltOnBuffProcs "ChaosBoltOnBuffProcs" default)
AddCheckBox(AutoHavoc "AutoHavoc" default)
AddCheckBox(DummyAutoHavoc "DummyAutoHavoc")
AddCheckBox(HavocOnlyOnChaosBolt "HavocOnlyOn_CB-SB-FOCUSED")
AddCheckBox(AutoRain "AutoRain")

AddCheckBox(RainOnSingleTarget "RainOnSingleTarget")

AddCheckBox(AutoCastPet "AutoCastPet")

AddCheckBox(AutoHeal "AutoHeal")
AddCheckBox(AvoidKillPlayer "AvoidKillPlayer" default)

#Daemons
AddListItem(Daemons Felhunter "Felhunter-Observer" default)
AddListItem(Daemons Succubus "Succubus-Shivarra")
AddListItem(Daemons Void "Void_Walker-VoidLord")
AddListItem(Daemons Imp "Imp-Fel_Imp")

AddFunction SummonDaemons
{
	if TalentPoints(grimoire_of_supremacy_talent)
	{
		if List(Daemons Felhunter)
			unless PetPresent() Spell(summon_observer)
		if List(Daemons Succubus)
			unless PetPresent() Spell(summon_shivarra)
		if List(Daemons Void)
			unless PetPresent() Spell(summon_voidlord)
		if List(Daemons Imp)
			unless PetPresent() Spell(summon_fel_imp)
	}
	if TalentPoints(grimoire_of_sacrifice_talent) or not TalentPoints(grimoire_of_supremacy_talent)
	{
		if List(Daemons Felhunter)
		{
			unless {PetPresent() and pet.CreatureFamily(Felhunter)} or BuffPresent(grimoire_of_sacrifice) Spell(summon_felhunter)
			if TalentPoints(grimoire_of_sacrifice_talent) and {PetPresent() and pet.CreatureFamily(Felhunter)} and not BuffPresent(grimoire_of_sacrifice) Spell(grimoire_of_sacrifice)
		}
		if List(Daemons Succubus)
		{
			unless {PetPresent() and pet.CreatureFamily(Succubus)} or BuffPresent(grimoire_of_sacrifice) Spell(summon_succubus)
			if TalentPoints(grimoire_of_sacrifice_talent) and {PetPresent() and pet.CreatureFamily(Succubus)} and not BuffPresent(grimoire_of_sacrifice) Spell(grimoire_of_sacrifice)
		}
		if List(Daemons Void)
		{
			unless {PetPresent() and pet.CreatureFamily(Voidwalker)} or BuffPresent(grimoire_of_sacrifice) Spell(summon_voidwalker)
			if TalentPoints(grimoire_of_sacrifice_talent) and {PetPresent() and pet.CreatureFamily(Succubus)} and not BuffPresent(grimoire_of_sacrifice) Spell(grimoire_of_sacrifice)
		}
		if List(Daemons Imp)
		{
			unless {PetPresent() and pet.CreatureFamily(Imp)} or BuffPresent(grimoire_of_sacrifice) Spell(summon_imp)
			if TalentPoints(grimoire_of_sacrifice_talent) and {PetPresent() and pet.CreatureFamily(Imp)} and not BuffPresent(grimoire_of_sacrifice) Spell(grimoire_of_sacrifice)
		}
	}
}


#Autoheal
AddListItem(Autoheal ah2 "Autoheal 20%")
AddListItem(Autoheal ah3 "Autoheal 30%")
AddListItem(Autoheal ah4 "Autoheal 40%" default)
AddListItem(Autoheal ah5 "Autoheal 50%")
AddListItem(Autoheal ah6 "Autoheal 60%")
AddListItem(Autoheal ah7 "Autoheal 70%")



AddFunction AutohealValue asValue=1
{
	if List(Autoheal ah2) 20
	if List(Autoheal ah3) 30
	if List(Autoheal ah4) 40
	if List(Autoheal ah5) 50
	if List(Autoheal ah6) 60
	if List(Autoheal ah7) 70
   
}

AddFunction Heal

{
    
	if CheckBoxOn(AutoHeal) and player.HealthPercent() <= 70 and PetPresent() and pet.Health() > 0 and  {pet.CreatureFamily(Imp) or pet.CreatureFamily(FelImp)}  Spell(cauterize_master)
    
	if CheckBoxOn(AutoHeal) and player.HealthPercent() <= AutohealValue()
    
	{
       
		focus.Item(healthstone usable=1)           
		if {{BurningEmbers() / 10} >=1} Spell(ember_tap)
    
	}

}

#DarkSoul
AddListItem(DarkSoulAtEmbers ds0 "DarkSoulAtEmbers 0")
AddListItem(DarkSoulAtEmbers ds1 "DarkSoulAtEmbers 1")
AddListItem(DarkSoulAtEmbers ds2 "DarkSoulAtEmbers 2" default)
AddListItem(DarkSoulAtEmbers ds3 "DarkSoulAtEmbers 3")

AddFunction DarkSoulAtEmbersValue asValue=1
{
	if List(DarkSoulAtEmbers ds0) 0
	if List(DarkSoulAtEmbers ds1) 1
	if List(DarkSoulAtEmbers ds2) 2
	if List(DarkSoulAtEmbers ds3) 3
   
}


#ChaosBolt
AddListItem(ChaosBoltMaxEmbers cb1 "ChaosBoltMaxEmbers 1")
AddListItem(ChaosBoltMaxEmbers cb15 "ChaosBoltMaxEmbers 1.5")
AddListItem(ChaosBoltMaxEmbers cb2 "ChaosBoltMaxEmbers 2")
AddListItem(ChaosBoltMaxEmbers cb25 "ChaosBoltMaxEmbers 2.5")
AddListItem(ChaosBoltMaxEmbers cb3 "ChaosBoltMaxEmbers 3" default)
AddListItem(ChaosBoltMaxEmbers cb35 "ChaosBoltMaxEmbers 3.5")

AddFunction ChaosBoltMaxEmbersValue asValue=1
{
	if List(ChaosBoltMaxEmbers cb1) 1
	if List(ChaosBoltMaxEmbers cb15) 1.5
	if List(ChaosBoltMaxEmbers cb2) 2
	if List(ChaosBoltMaxEmbers cb25) 2.5
	if List(ChaosBoltMaxEmbers cb3) 3
	if List(ChaosBoltMaxEmbers cb35) 3.5
   
}


##
#trinket SiageOfOgrimmar proc
##

Define(Expanded_Mind 146046)  		#Purified Bindings of Immerseus
Define(Toxic_Power 148906)    		#Kardris' Toxic Totem
Define(Wrath_of_the_Darkspear 146184) 	#Black Blood of Y'Shaarj (stacks 10 times) BuffStacks
Define(Extravagant_Visions 148897)	#Frenzied Crystal of Rage
Define(Yu_lon_Bite 146218)		#Yu'lon's Bite (crit)

AddFunction HasTrinketBuffForChaosBolt
{
	BuffRemains(Expanded_Mind) > CastTime(chaos_bolt) or
	BuffRemains(Toxic_Power) > CastTime(chaos_bolt) or
	BuffRemains(Wrath_of_the_Darkspear) > CastTime(chaos_bolt) or
	BuffRemains(Extravagant_Visions) > CastTime(chaos_bolt) or
	BuffRemains(Yu_lon_Bite) > CastTime(chaos_bolt)
}


##
##Destruction
##

AddFunction Interrupt
{
	if CheckBoxOn(AutoInterrupt) and {target.IsFriend(no) or {target.IsFriend() and target.IsCharmed()} } and target.IsInterruptible()
	{
		if TalentPoints(grimoire_of_sacrifice_talent) and target.InRange(chaos_bolt)
		{
			if Spell(spell_lock_sacrifice)	Spell(command_demon)
		}
		if target.InRange(chaos_bolt) and PetPresent() and pet.Health() > 0 
		{
			if pet.CreatureFamily(Felhunter) Spell(spell_lock)
			if pet.CreatureFamily(Observer) Spell(Optical_Blast)
		}
		Spell(shadowfury)
	}
}

AddFunction FullRotationSingleTarget
{
	Heal()
	if BuffPresent(fire_and_brimstone) Texture(fire_and_brimstone)
        Interrupt()	
	unless BuffPresent(spell_power_multiplier any=1) Spell(dark_intent)
	if CheckBoxOn(AutoCastPet) SummonDaemons()
	if ItemCount(healthstone less 1) Spell(create_healthstone)
	
	if CheckBoxOn(AvoidKillPlayer) and target.IsPlayer()
	{
		if target.InRange(conflagrate) Spell(conflagrate)
		if InCombat() and Speed()==0 and CheckBoxOn(AutoRain) and CheckBoxOn(RainOnSingleTarget) and not BuffPresent(rain_of_fire) Spell(rain_of_fire)
		if target.InRange(conflagrate) and {Speed()==0 or TalentPoints(cunning_talent)} Spell(incinerate)
		if Speed() > 0 and not TalentPoints(cunning_talent) Spell(fel_flame)
	}
	if CheckBoxOn(AutoCurseOfElements) and target.InRange(curse_of_the_elements)
	{
		if target.DebuffRemains(magic_vulnerability any=1 atMost 2) Spell(curse_of_the_elements)
	}

	if InCombat() and CheckBoxOn(AutoDarkSoul) and {{BurningEmbers() / 10} >= DarkSoulAtEmbersValue()} Spell(dark_soul_instability)
	if Charges(conflagrate equal 2) and target.InRange(conflagrate) Spell(conflagrate)
	
	if {{BurningEmbers() / 10} >=1} and target.HealthPercent(atMost 20) and target.InRange(conflagrate) and target.TimeToDie() < 5
	{
		if {Enemies() >= 2 or CheckBoxOn(DummyAutoHavoc)} and CheckBoxOn(AutoHavoc) and CheckBoxOn(HavocOnlyOnChaosBolt) and focus.InRange(conflagrate) focus.Spell(havoc)
		Spell(shadowburn)
	}
	
	if {{BurningEmbers() / 10} >=1} and target.InRange(chaos_bolt) 
	{	
		
		if {BurningEmbers() / 10} >= ChaosBoltMaxEmbersValue() or  BuffRemains(skull_banner) > CastTime(chaos_bolt) 
			or BuffRemains(dark_soul_instability) > CastTime(chaos_bolt) 
			or HasTrinketBuffForChaosBolt()
		{
			if {Enemies() >= 2 or CheckBoxOn(DummyAutoHavoc)} and CheckBoxOn(AutoHavoc) and CheckBoxOn(HavocOnlyOnChaosBolt) and focus.InRange(conflagrate) focus.Spell(havoc)
			if Speed()==0 Spell(chaos_bolt)
		}

	}
	if Speed()==0 and {target.DebuffExpires(destro_combined_dots) or {target.DebuffRemains(destro_combined_dots) < {CastTime(immolate) +CastTime(incinerate) +1.5}}} and target.DeadIn(atLeast 5) Spell(immolate)
	
	if InCombat() and CheckBoxOn(AutoDoomGuard) Spell(summon_doomguard)
	if {Enemies() >= 2 or CheckBoxOn(DummyAutoHavoc)} and CheckBoxOn(AutoHavoc) and not CheckBoxOn(HavocOnlyOnChaosBolt) and target.InRange(conflagrate) Spell(havoc)	
	if target.InRange(conflagrate) Spell(conflagrate)
	if InCombat() and Speed()==0 and CheckBoxOn(AutoRain) and CheckBoxOn(RainOnSingleTarget) and not BuffPresent(rain_of_fire) Spell(rain_of_fire)
	if target.InRange(conflagrate) and {Speed()==0 or TalentPoints(cunning_talent)} Spell(incinerate)
	if Speed() > 0 and not TalentPoints(cunning_talent) Spell(fel_flame)
}

AddFunction FullRotationAOE
{
	Heal()
	if not BuffPresent(fire_and_brimstone) and {BurningEmbers() / 10} >=1 Spell(fire_and_brimstone)
        Interrupt()	
	unless BuffPresent(spell_power_multiplier any=1) Spell(dark_intent)
	if CheckBoxOn(AutoCastPet) SummonDaemons()
	if ItemCount(healthstone less 1) Spell(create_healthstone)

	if CheckBoxOn(AutoCurseOfElements) and target.InRange(curse_of_the_elements)
	{
		if target.DebuffRemains(magic_vulnerability any=1 atMost 2) Spell(curse_of_the_elements)
	}

	if {{BurningEmbers() / 10} >=1} and target.HealthPercent(atMost 20) and target.InRange(conflagrate) and target.TimeToDie() < 4
	{
		if {Enemies() >= 2 or CheckBoxOn(DummyAutoHavoc)} and CheckBoxOn(AutoHavoc) and CheckBoxOn(HavocOnlyOnChaosBolt) and focus.InRange(conflagrate) focus.Spell(havoc)
		Spell(shadowburn)
	}

	if InCombat() and CheckBoxOn(AutoDarkSoul) and {{BurningEmbers() / 10} >= 1} Spell(dark_soul_instability)	
	if Speed()==0 and BuffPresent(fire_and_brimstone) and {target.DebuffExpires(immolate_fire_and_brimstone) or {target.DebuffRemains(immolate_fire_and_brimstone) < {CastTime(immolate) +CastTime(incinerate) +1.5}}} and target.DeadIn(atLeast 5) Spell(immolate_fire_and_brimstone)
	if InCombat() and Speed()==0 and CheckBoxOn(AutoRain) and not BuffPresent(rain_of_fire) Spell(rain_of_fire)
	if InCombat() and CheckBoxOn(AutoDoomGuard) Spell(summon_infernal)
	if target.InRange(conflagrate) Spell(conflagrate)	
	if target.InRange(conflagrate) and {Speed()==0 or TalentPoints(cunning_talent)} Spell(incinerate_aoe)
	if target.InRange(conflagrate) and not BuffPresent(fire_and_brimstone) and {Speed()==0 or TalentPoints(cunning_talent)} Spell(incinerate)
}

AddIcon specialization=3 help=SingleTarget
{
	FullRotationSingleTarget()	
}

AddIcon specialization=3 help=SingleTarget
{
	FullRotationAOE()	
}







]],
}
